home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news!enno
- From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
- Newsgroups: comp.lang.c++
- Subject: Re: Overloading conversion
- Date: 14 Jan 1996 10:18:25 GMT
- Organization: Fachbereich Informatik, TH Darmstadt
- Distribution: world
- Message-ID: <ENNO.96Jan14111826@kitz.inferenzsysteme.informatik.th-darmstadt.de>
- References: <4d934v$10hs@ds2.acs.ucalgary.ca>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- In-reply-to: hdang@acs3.acs.ucalgary.ca's message of 13 Jan 1996 20:02:39 GMT
-
- In article <4d934v$10hs@ds2.acs.ucalgary.ca> hdang@acs3.acs.ucalgary.ca (Hanna Dang) writes:
-
- Is there a way to overload functions such that certain
- functions are called depending on the context the object are
- used. For example,
-
- class T {
- public:
- int& int_value() { modified = TRUE; return value;}
- int int_value() {return value;}
- private:
- int value;
- int modified;
- }
-
-
- ...
-
- T a;
- int test = a + 6 // int int_value should be called;
- a = 20 // int& int_value should be called.
-
- However, this does not work because in both case int& int_value
- is called. Is there another way to find out if value is changed
- or it's just inspected.
-
- Yes -- make the latter 'int_value' a const member-function, ie.
-
- int int_value() const {return value;}
-
- Enno
-